Package com.gui

Source Code of com.gui.FishInfoWindow

package com.gui;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import com.fish.Fish;
import com.fish.World;


public class FishInfoWindow extends Menu implements ActionListener {
  /**
   *
   */
  private static final long serialVersionUID = 1L;
 
 
  Fish selectedFish = null;
  JLabel info;
  JButton closeButton;
  JButton focusButton;
  JButton viewFromFishEyesButton;
  JButton sellFishButton;
 
  public FishInfoWindow() {
    super();
   
    info = new JLabel("");
    info.setFocusable(false);   
   
    focusButton = new JButton("Focus");
    focusButton.setFocusable(false);   
    focusButton.setBackground(lvl3);   
    focusButton.addActionListener(this);
   
    viewFromFishEyesButton = new JButton("Enter fish perspective");
    viewFromFishEyesButton.setFocusable(false);   
    viewFromFishEyesButton.setBackground(lvl3);
    viewFromFishEyesButton.addActionListener(this);
   
    sellFishButton = new JButton("Sell for: ");
    sellFishButton.setFocusable(false);   
    sellFishButton.setBackground(lvl3);   
    sellFishButton.addActionListener(this);
   
    closeButton = new JButton("close");
    closeButton.setFocusable(false);   
    closeButton.setBackground(lvl2);   
    closeButton.addActionListener(this);
   
    this.setFocusable(false);  
    this.setBackground(bg12);
   
    GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);
    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);
   
   
    layout.setVerticalGroup(layout.createParallelGroup()
        .addGroup(layout.createParallelGroup()
            .addComponent(closeButton)
            .addComponent(info)
            )
        .addGroup(layout.createSequentialGroup()
            .addComponent(focusButton)
            .addComponent(viewFromFishEyesButton)
            .addComponent(sellFishButton)));
   
    layout.linkSize(SwingConstants.HORIZONTAL, focusButton,viewFromFishEyesButton,sellFishButton,info);
   
    layout.setHorizontalGroup(layout.createSequentialGroup()
        .addGroup(layout.createSequentialGroup()
            .addComponent(closeButton)
            .addComponent(info)
            )
        .addGroup(layout.createParallelGroup()
            .addComponent(focusButton)
            .addComponent(viewFromFishEyesButton)
            .addComponent(sellFishButton)));
   
    this.setVisible(false);
  }

  public void paintComponent(Graphics g){
    labelUpdate();
    super.paintComponent(g);
  }
 
  public void labelUpdate(){
    String s = "<html><body>" +
          "Fish information:<br>" +
          "Name: " + selectedFish.name + "<br>" +
          "Type: " + selectedFish.type + "<br>" +
          "Age: " +  Math.round(selectedFish.age) + "<br>" +
          "Status: " + selectedFish.status + "<br>" +
          "Size: " +  Math.round(selectedFish.size) + "<br>" +
          "Health: " +  Math.round(selectedFish.health) + "<br>" +
          "General information: " + selectedFish.ginfo + "<br>" +
          "Value: " + Math.round(selectedFish.value) + "<br>" +
          "</body></html>";

    info.setText(s);
   
    sellFishButton.setText("sell for: " +  Math.round(selectedFish.value) + "$");
  }
 
 
  public void clickedOnFish(Fish f){
   
    selectedFish = f;
   
    this.setVisible(true);
  }
 
  @Override
  public void actionPerformed(ActionEvent e) {
    Object obj = e.getSource();
    if(obj == sellFishButton){
      World.money += selectedFish.value;
      World.shapes.remove(selectedFish);
      this.setVisible(false);
    }else if(obj == focusButton){
      if(focusButton.getText() == "Focus"){
        World.cam.follow(selectedFish);
        focusButton.setText("Unfocus");
      }else{
        World.cam.reset();
        focusButton.setText("Focus");
      }
    }else if(obj == viewFromFishEyesButton){
      if(viewFromFishEyesButton.getText() == "Enter fish perspective"){
        World.cam.fromEyes(selectedFish);
        viewFromFishEyesButton.setText("Exit fish perspective");
      }else{
        World.cam.reset();
        viewFromFishEyesButton.setText("Enter fish perspective");
      }
    }
    else if(obj == closeButton){
      this.setVisible(false);
    }
  }
}
TOP

Related Classes of com.gui.FishInfoWindow

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.